using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebMenu
{
    public partial class WUC_ToggleButton : System.Web.UI.UserControl
    {
        public event EventHandler eventToggle_On;
        public event EventHandler eventToggle_Off;

        // Toggle State
        public enum ToggleButtonState
        {
            On = 0,
            Off = 1,
        }
        public ToggleButtonState toggleState
        {
            get
            {
                if (ViewState["toggleState"] == null)
                    ViewState["toggleState"] = ToggleButtonState.On;
                return (ToggleButtonState)ViewState["toggleState"];
            }
            set { ViewState["toggleState"] = value; }
        }


        // Toggle parameters: Allow user to specify on, off labels as parameters via html link in Designer
        public string onText;
        public string offText;

        public string OnText
        {
            get { return onText; }
            set { onText = value; }
        }
        public string OffText
        {
            get { return offText; }
            set { offText = value; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnToggle01_Click(object sender, EventArgs e)
        {
            if (this.toggleState == ToggleButtonState.On)
            {
                toggleState = ToggleButtonState.Off;
                btnToggle01.Text = this.OffText;
                if (eventToggle_On != null)
                {
                    eventToggle_On(this, new EventArgs());
                }
            }
            else
            {
                toggleState = ToggleButtonState.On;
                btnToggle01.Text = this.OnText;
                if (eventToggle_Off != null)
                {
                    eventToggle_Off(this, new EventArgs());
                }
            }

        }

        // Tests
        public void btnToggle01_On() {
            toggleState = ToggleButtonState.Off;
            btnToggle01.Text = this.OffText;
            if (eventToggle_On != null)
            {
                eventToggle_On(this, new EventArgs());
            }
        }
        public void btnToggle01_Off()
        {
            toggleState = ToggleButtonState.On;
            btnToggle01.Text = this.OnText;
            if (eventToggle_Off != null)
            {
                eventToggle_Off(this, new EventArgs());
            }
        }
        public void btnToggle01_setText(string stext)
        {
            btnToggle01.Text = stext;
        }



    }
}